<?php

namespace Application\Service;

class ErrorHandling {
	protected $logger;
	
	function __construct($logger)
	{
		$this->logger = $logger;
	}
	
	function logException(\Exception $e)
	{
		$trace = $e->getTraceAsString();
		$i = 1;
		do {
			$messages[] = $i++ . ": " . $e->getMessage();
		} while ($e = $e->getPrevious());
	
		$log = "\n\r\n\rException:\n\r\n\r" . implode("\n\r\n\r", $messages);
		$log .= "\n\r\n\rTrace:\n\r\n\r" . $trace;
	
		$this->logger->err($log);
	}
}

?>